import pymysql  
#2.插入操作  
db= pymysql.connect(host="localhost",user="root",  
    password="",db="zsmdb",port=3306)   
  
# 使用cursor()方法获取操作游标  
cur = db.cursor()  
  
sql_insert = "INSERT INTO users(name,psw,email,mobile,usersex) VALUES('Wu','1234','wdl@163.com','1234567','man')"  
  
try:  
	cur.execute(sql_insert)
	print('execut ok')
	  
	#提交  
	db.commit()  
except Exception as e:  
	#错误回滚  
	#db.rollback() 
	print('execute sql err')
finally:  
	db.close() 